package com.dynamixsoftware.printershare.bt;

import android.bluetooth.IBluetoothDeviceCallback;
import android.bluetooth.IBluetoothDeviceCallback.Stub;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.os.RemoteException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.UUID;

class BTAdapterImpl16
  extends BTAdapter
{
  private Object bd;
  private Field bd_BOND_BONDED;
  private Method bd_cancelDiscovery;
  private Method bd_createBond;
  private Method bd_getBondState;
  private Method bd_getRemoteClass;
  private Method bd_getRemoteName;
  private Method bd_getRemoteServiceChannel;
  private Method bd_isDiscovering;
  private Method bd_isEnabled;
  private Method bd_startDiscovery;
  private Class<?> rfs;
  private Method rfs_connect;
  private Method rfs_create;
  private Method rfs_destroy;
  private Method rfs_getInputStream;
  private Method rfs_getOutputStream;
  
  private BTAdapterImpl16(Object paramObject)
    throws Exception
  {
    this.bd = paramObject;
    Class localClass1 = paramObject.getClass();
    this.bd_BOND_BONDED = localClass1.getField("BOND_BONDED");
    this.bd_isEnabled = localClass1.getMethod("isEnabled", new Class[0]);
    this.bd_isDiscovering = localClass1.getMethod("isDiscovering", new Class[0]);
    this.bd_startDiscovery = localClass1.getMethod("startDiscovery", new Class[0]);
    this.bd_cancelDiscovery = localClass1.getMethod("cancelDiscovery", new Class[0]);
    this.bd_getRemoteName = localClass1.getMethod("getRemoteName", new Class[] { String.class });
    this.bd_getRemoteClass = localClass1.getMethod("getRemoteClass", new Class[] { String.class });
    try
    {
      Class[] arrayOfClass2 = new Class[3];
      arrayOfClass2[0] = String.class;
      arrayOfClass2[1] = Short.TYPE;
      arrayOfClass2[2] = Class.forName("android.bluetooth.IBluetoothDeviceCallback");
      this.bd_getRemoteServiceChannel = localClass1.getMethod("getRemoteServiceChannel", arrayOfClass2);
      label158:
      this.bd_getBondState = localClass1.getMethod("getBondState", new Class[] { String.class });
      this.bd_createBond = localClass1.getMethod("createBond", new Class[] { String.class });
      this.rfs = Class.forName("android.bluetooth.RfcommSocket");
      this.rfs_create = this.rfs.getMethod("create", new Class[0]);
      Class localClass2 = this.rfs;
      Class[] arrayOfClass1 = new Class[2];
      arrayOfClass1[0] = String.class;
      arrayOfClass1[1] = Integer.TYPE;
      this.rfs_connect = localClass2.getMethod("connect", arrayOfClass1);
      this.rfs_getInputStream = this.rfs.getMethod("getInputStream", new Class[0]);
      this.rfs_getOutputStream = this.rfs.getMethod("getOutputStream", new Class[0]);
      this.rfs_destroy = this.rfs.getMethod("destroy", new Class[0]);
      return;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      break label158;
    }
    catch (NoSuchMethodException localNoSuchMethodException)
    {
      break label158;
    }
  }
  
  public static BTAdapter getDefault(Context paramContext)
    throws Exception
  {
    Object localObject = paramContext.getSystemService("bluetooth");
    if (localObject != null) {
      return new BTAdapterImpl16(localObject);
    }
    return null;
  }
  
  boolean createBond(String paramString)
    throws Exception
  {
    return ((Boolean)this.bd_createBond.invoke(this.bd, new Object[] { paramString })).booleanValue();
  }
  
  BTSocket createInsecureRfcommSocket(String paramString, int paramInt)
    throws Exception
  {
    return null;
  }
  
  BTSocket createInsecureRfcommSocketToServiceRecord(String paramString, UUID paramUUID)
    throws Exception
  {
    return null;
  }
  
  BTSocket createRfcommSocket(String paramString, int paramInt)
    throws Exception
  {
    return new SocketImpl(paramString, paramInt);
  }
  
  BTSocket createRfcommSocketToServiceRecord(String paramString, UUID paramUUID)
    throws Exception
  {
//    if (this.bd_getRemoteServiceChannel != null) {
//      synchronized (new int[1])
//      {
//        Short localShort = Short.valueOf(Short.parseShort(paramUUID.toString().substring(4, 8), 16));
//        Method localMethod = this.bd_getRemoteServiceChannel;
//        Object localObject2 = this.bd;
//        Object[] arrayOfObject = new Object[3];
//        arrayOfObject[0] = paramString;
//        arrayOfObject[1] = localShort;
//        arrayOfObject[2] = Class.forName(getClass().getName() + "$BDC").getConstructor(new Class[] { String.class, [I.class }).newInstance(new Object[] { paramString, ??? });
//        localMethod.invoke(localObject2, arrayOfObject);
//        ???.wait(10000L);
//        int i = ???[0];
//        BTSocket localBTSocket = null;
//        if (i > 0) {
//          localBTSocket = createRfcommSocket(paramString, ???[0]);
//        }
//        return localBTSocket;
//      }
//    }
    return null;
  }
  
  public void doCancelDiscovery()
    throws Exception
  {
    this.bd_cancelDiscovery.invoke(this.bd, new Object[0]);
  }
  
  public void doStartDiscovery()
    throws Exception
  {
    this.bd_startDiscovery.invoke(this.bd, new Object[0]);
  }
  
  boolean getBondState(String paramString)
    throws Exception
  {
    return this.bd_BOND_BONDED.get(null).equals(this.bd_getBondState.invoke(this.bd, new Object[] { paramString }));
  }
  
  public String getBondStateChangedIntentAction()
  {
    return "android.bluetooth.intent.action.BOND_STATE_CHANGED_ACTION";
  }
  
  public IntentFilter getDiscoveryIntentFilter()
  {
    IntentFilter localIntentFilter = new IntentFilter();
    localIntentFilter.addAction("android.bluetooth.intent.action.REMOTE_DEVICE_FOUND");
    localIntentFilter.addAction("android.bluetooth.intent.action.REMOTE_CLASS_UPDATED");
    localIntentFilter.addAction("android.bluetooth.intent.action.REMOTE_NAME_UPDATED");
    return localIntentFilter;
  }
  
  public BTDevice getRemoteDevice(String paramString)
    throws Exception
  {
    return new BTDevice(this, paramString, (String)this.bd_getRemoteName.invoke(this.bd, new Object[] { paramString }), (Integer)this.bd_getRemoteClass.invoke(this.bd, new Object[] { paramString }));
  }
  
  public boolean isDiscovering()
    throws Exception
  {
    return ((Boolean)this.bd_isDiscovering.invoke(this.bd, new Object[0])).booleanValue();
  }
  
  public boolean isEnabled()
    throws Exception
  {
    return ((Boolean)this.bd_isEnabled.invoke(this.bd, new Object[0])).booleanValue();
  }
  
  public BTDevice parseDiscoveryIntentResult(Intent paramIntent)
    throws Exception
  {
    if (paramIntent != null)
    {
      String str1 = paramIntent.getStringExtra("android.bluetooth.intent.ADDRESS");
      if (str1 != null)
      {
        String str2 = paramIntent.getStringExtra("android.bluetooth.intent.NAME");
        if ((str2 == null) || ("".equals(str2))) {
          str2 = (String)this.bd_getRemoteName.invoke(this.bd, new Object[] { str1 });
        }
        return new BTDevice(this, str1, str2, (Integer)this.bd_getRemoteClass.invoke(this.bd, new Object[] { str1 }));
      }
    }
    return null;
  }
  
  static class BDC
    implements IBluetoothDeviceCallback
  {
    String address;
    IBinder binder = new IBluetoothDeviceCallback.Stub()
    {
      public void onGetRemoteServiceChannelResult(String paramAnonymousString, int paramAnonymousInt)
        throws RemoteException
      {
        if (paramAnonymousString.equals(BTAdapterImpl16.BDC.this.address)) {
          synchronized (BTAdapterImpl16.BDC.this.ch)
          {
            BTAdapterImpl16.BDC.this.ch[0] = paramAnonymousInt;
            BTAdapterImpl16.BDC.this.ch.notifyAll();
            return;
          }
        }
      }
    };
    int[] ch;
    
    public BDC(String paramString, int[] paramArrayOfInt)
    {
      this.address = paramString;
      this.ch = paramArrayOfInt;
    }
    
    public IBinder asBinder()
    {
      return this.binder;
    }
    
    public void onGetRemoteServiceChannelResult(String paramString, int paramInt)
      throws RemoteException
    {}
  }
  
  class SocketImpl
    extends BTSocket
  {
    private String address;
    private int channel;
    Object sk;
    
    SocketImpl(String paramString, int paramInt)
      throws Exception
    {
      this.address = paramString;
      this.channel = paramInt;
      this.sk = BTAdapterImpl16.this.rfs.newInstance();
      BTAdapterImpl16.this.rfs_create.invoke(this.sk, new Object[0]);
    }
    
    protected boolean connect()
      throws Exception
    {
      Method localMethod = BTAdapterImpl16.this.rfs_connect;
      Object localObject = this.sk;
      Object[] arrayOfObject = new Object[2];
      arrayOfObject[0] = this.address;
      arrayOfObject[1] = Integer.valueOf(this.channel);
      return ((Boolean)localMethod.invoke(localObject, arrayOfObject)).booleanValue();
    }
    
    public void destroy()
      throws Exception
    {
      BTAdapterImpl16.this.rfs_destroy.invoke(this.sk, new Object[0]);
    }
    
    public InputStream getInputStream()
      throws Exception
    {
      return (InputStream)BTAdapterImpl16.this.rfs_getInputStream.invoke(this.sk, new Object[0]);
    }
    
    public OutputStream getOutputStream()
      throws Exception
    {
      return (OutputStream)BTAdapterImpl16.this.rfs_getOutputStream.invoke(this.sk, new Object[0]);
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.bt.BTAdapterImpl16
 * JD-Core Version:    0.7.0.1
 */